import Vue from 'vue'
import Router from 'vue-router'
//import Home from '@/views/home/Home.vue'
import Main from '@/views/Main.vue'
//import UserList from '@views/user/UserList.vue'
import UserList from '@/views/UserList'
import UserInfo from '@/views/UserInfo'
import GoodsList from '@/views/GoodsList'
import GoodsInfo from '@/views/GoodsInfo'
import User from '@/views/User'
import Register from '@/views/register/Register'
import Goods from '@/views/goods/Goods'
import ViewUI from 'view-design';
Vue.use(ViewUI);
Vue.use(Router)

let router = new Router({
  routes: [{
      path: '/',
      name: 'Home', 
      meta: {
        title: "平台"},
      component: Main,
      redirect: '/user',
      children: [{
        path: '/user',
          meta: {
            title: "用户"
          },
          component: User
      },{
        path: '/user/list', 
        meta: {
          parentTitle:'用户管理',
          title: "用户数据"
        },
        component: UserList
      }, {
        path: '/user/info',
        meta: {
          parentTitle: '用户管理',
          title: "用户信息"
        },
        component: UserInfo
      }, {
        path: '/goods/list',
        meta: {
          parentTitle: '商品管理',
          title: "商品数据"
        },
        component: GoodsList
      }, {
        path: '/goods/info',
        meta: {
          parentTitle: '商品管理',
          title: "商品信息"
        },
        component: GoodsInfo
      }, {
        path:'/goods',
        meta:{
          title:'商品'
        },
        component:Goods
      }]
    }
    /* ,{
        path:'/userlist',
        name: 'UserList',
        component: UserList
      } */
    , {
      path: '/login',
      name: 'Register',
      meta: {
        title: "登录",
        anonymous:true
      },
      component: Register
    }
  ]
  /* , {
      path: '/city',
      name: 'City',
      component: City
    }, {
      path: '/detail/:id',
      name: 'Detail',
      component: Detail
    }], */
})

router.beforeEach((to, from, next) => {
  ViewUI.LoadingBar.start();
  //if (to.path !== '/login' && !sessionStorage.getItem('loginuser')) {
  if (!to.meta.anonymous && !sessionStorage.getItem('loginuser')) {
    next('/login')
  }
  next();
});

router.afterEach((to) => {
  ViewUI.LoadingBar.finish();
  document.title=to.meta.title
});

export default router
